<script setup>
import { ref } from 'vue'

// 统计数据
const statistics = ref([
  { title: '用户总数', value: 8846, icon: 'User', color: '#409EFF' },
  { title: '订单总数', value: 1234, icon: 'ShoppingCart', color: '#67C23A' },
  { title: '产品总数', value: 356, icon: 'Goods', color: '#E6A23C' },
  { title: '收益总额', value: '¥123,456', icon: 'Money', color: '#F56C6C' }
])

// 图表数据 (模拟)
const chartData = ref({
  labels: ['一月', '二月', '三月', '四月', '五月', '六月'],
  datasets: [
    { name: '用户增长', data: [30, 40, 45, 50, 49, 60] },
    { name: '收益', data: [10, 20, 30, 40, 35, 55] }
  ]
})

// 最近活动
const activities = ref([
  { content: '张三 完成了任务 A', timestamp: '10分钟前' },
  { content: '系统更新已完成', timestamp: '30分钟前' },
  { content: '李四 提交了新订单', timestamp: '1小时前' },
  { content: '王五 评论了产品B', timestamp: '2小时前' },
  { content: '系统维护通知', timestamp: '1天前' }
])
</script>

<template>
  <div class="home-container">
    <!-- 欢迎信息 -->
    <div class="welcome-section">
      <h1>欢迎使用 Vue Admin 管理系统</h1>
      <p>今天是 {{ new Date().toLocaleDateString() }}，祝您工作愉快！</p>
    </div>

    <!-- 统计卡片 -->
    <div class="stat-cards">
      <el-row :gutter="20">
        <el-col :span="6" v-for="(item, index) in statistics" :key="index">
          <el-card shadow="hover" class="stat-card">
            <div class="stat-icon" :style="{ backgroundColor: item.color }">
              <el-icon><component :is="item.icon" /></el-icon>
            </div>
            <div class="stat-info">
              <div class="stat-title">{{ item.title }}</div>
              <div class="stat-value">{{ item.value }}</div>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </div>

    <!-- 图表和活动 -->
    <el-row :gutter="20" class="chart-row">
      <el-col :span="16">
        <el-card shadow="hover" class="chart-card">
          <template #header>
            <div class="card-header">
              <span>数据分析</span>
            </div>
          </template>
          <div class="chart-placeholder">
            <!-- 这里应该放真实的图表组件，目前用占位符代替 -->
            <div class="chart-mock">
              <div v-for="(dataset, i) in chartData.datasets" :key="i" class="chart-line">
                <div class="chart-legend" :style="{ backgroundColor: i === 0 ? '#409EFF' : '#67C23A' }"></div>
                <span>{{ dataset.name }}</span>
              </div>
              <div class="chart-bars">
                <div v-for="(month, i) in chartData.labels" :key="i" class="chart-bar-group">
                  <div class="chart-bar" :style="{ height: chartData.datasets[0].data[i] + 'px', backgroundColor: '#409EFF' }"></div>
                  <div class="chart-bar" :style="{ height: chartData.datasets[1].data[i] + 'px', backgroundColor: '#67C23A' }"></div>
                  <div class="chart-label">{{ month }}</div>
                </div>
              </div>
            </div>
          </div>
        </el-card>
      </el-col>

      <el-col :span="8">
        <el-card shadow="hover" class="activity-card">
          <template #header>
            <div class="card-header">
              <span>最近活动</span>
            </div>
          </template>
          <div class="activity-list">
            <el-timeline>
              <el-timeline-item
                v-for="(activity, index) in activities"
                :key="index"
                :timestamp="activity.timestamp"
                placement="top"
              >
                {{ activity.content }}
              </el-timeline-item>
            </el-timeline>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<style scoped>
.home-container {
  padding: 20px;
  height: calc(100% - 40px);
  overflow: auto;
}

.welcome-section {
  margin-bottom: 25px;
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
}

.welcome-section h1 {
  font-size: 24px;
  font-weight: 600;
  margin: 0 0 10px 0;
  color: #303133;
  position: relative;
  display: inline-block;
}

.welcome-section h1:after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 0;
  width: 30px;
  height: 3px;
  background-color: #409EFF;
  border-radius: 3px;
}

.welcome-section p {
  font-size: 14px;
  color: #606266;
  margin: 0;
}

.stat-cards {
  margin-bottom: 25px;
}

.stat-card {
  height: 100px;
  display: flex;
  align-items: center;
}

.stat-icon {
  width: 60px;
  height: 60px;
  border-radius: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 15px;
  font-size: 24px;
  color: white;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

.stat-info {
  flex: 1;
}

.stat-title {
  font-size: 14px;
  color: #909399;
  margin-bottom: 5px;
}

.stat-value {
  font-size: 22px;
  font-weight: bold;
  color: #303133;
}

.chart-row {
  margin-bottom: 20px;
  display: flex;
  flex-wrap: wrap;
}

.chart-card, .activity-card {
  transition: all 0.3s;
}

.chart-card:hover, .activity-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1) !important;
}

.chart-placeholder {
  height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
  border-radius: 6px;
  padding: 20px;
}

.chart-mock {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.chart-line {
  display: flex;
  align-items: center;
  margin-bottom: 15px;
}

.chart-legend {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  margin-right: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.chart-bars {
  flex: 1;
  display: flex;
  align-items: flex-end;
  justify-content: space-around;
  border-bottom: 1px solid #ebeef5;
  border-left: 1px solid #ebeef5;
  padding: 20px 0;
  margin-top: 20px;
  position: relative;
}

.chart-bar-group {
  display: flex;
  align-items: flex-end;
  margin: 0 10px;
}

.chart-bar {
  width: 20px;
  margin: 0 5px;
  border-radius: 4px 4px 0 0;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  transition: all 0.3s;
}

.chart-bar:hover {
  transform: scaleY(1.05);
}

.chart-label {
  position: absolute;
  bottom: -25px;
  font-size: 12px;
  color: #909399;
  font-weight: 500;
}

.activity-card {
  height: 400px;
  overflow: auto;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 10px;
  border-bottom: 1px solid #f2f2f2;
}

.card-header span {
  font-size: 16px;
  font-weight: 600;
  color: #303133;
}

.activity-list {
  margin-top: 10px;
}

.activity-list :deep(.el-timeline-item__node) {
  background-color: #409EFF;
}

.activity-list :deep(.el-timeline-item__content) {
  color: #303133;
  font-weight: 500;
}

.activity-list :deep(.el-timeline-item__timestamp) {
  color: #909399;
}
</style>
